package com.ms.oschina.util;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;

import com.ms.oschina.base.AppContext;
import com.ms.oschina.bean.Constants;
import com.ms.oschina.ui.activity.ImagePreActivity;
import com.ms.oschina.ui.activity.LoginActivity;
import com.ms.oschina.ui.activity.NewsDetailsActivity;

/**
 * Created by Administrator on 2016/4/21.
 */
public class UiUtils {

	public static Context getContext() {
		return AppContext.getContext();
	}

	public static View inflate(int resId) {
		return View.inflate(AppContext.getContext(), resId, null);
	}

	public static void showToast(final String msg) {
		HandlerUtils.postTaskSafely(new Runnable() {
			@Override
			public void run() {
				Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
			}
		});
	}

	public static String[] getStringArray(int id) {
		String[] str = getContext().getResources().getStringArray(id);
		return str;
	}

	public static int getDimensionPixelSize(int id) {
		int size = getContext().getResources().getDimensionPixelSize(id);
		return size;
	}

	public static String getString(int id) {
		return getContext().getResources().getString(id);
	}

	public static int getColor(int color) {
		return getContext().getResources().getColor(color);
	}

	public static void login() {
		Context context = UiUtils.getContext();
		Intent intent = new Intent(context, LoginActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
	}

	public static void showImagePreview(Context context,String smallImageUrl, String bigImageUrl) {
		Intent intent = new Intent(context, ImagePreActivity.class);
		intent.putExtra(Constants.SMALL_IMAGE_URL, smallImageUrl);
		intent.putExtra(Constants.BIG_IMAGE_URL, bigImageUrl);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
	}

}
